{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2022/10/111/week08\n",
    "python课堂笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "0.代码的注释\n",
    "1.用户输入\n",
    "2.格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "0.代码的注释"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.#,一般写在代码块的最上边，或者每一行代码的最后，用于代码思路的记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Author：xue"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.'''注释内容'''，一般是注释代码块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "import random\n",
    "'''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.用户输入"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:1\n",
      "密码:2\n",
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:1\n",
      "密码:2\n",
      "账号不存在或密码不正确\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 迭代1 增加判断功能\n",
    "# 假设我们数据库有用户信息： 账号：Haha ，密码，123456\n",
    "user1 = \"Haha\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "# 情景一：输入信息正确，登陆成功\n",
    "if user1 == username and password1 ==password:\n",
    "    print(\"欢迎\"+user1+\"登陆！\")\n",
    "    \n",
    "\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:1\n",
      "密码:2\n",
      "账号不存在或密码不正确!\n",
      "您还有2次尝试的机会\n",
      "账号:2\n",
      "密码:2\n",
      "账号不存在或密码不正确!\n",
      "您还有1次尝试的机会\n",
      "账号:3\n",
      "密码:4\n",
      "三次输入失败，请1小时后再来尝试\n",
      "账号不存在或密码不正确!\n",
      "您还有0次尝试的机会\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 迭代1 增加循环功能\n",
    "# 假设我们数据库有用户信息： 账号：Haha ，密码，123456\n",
    "user1 = \"Haha\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1): # i是一个int\n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "    # 情景一：输入信息正确，登陆成功\n",
    "    if user1 == username and password1 ==password:\n",
    "        print(\"欢迎\"+user1+\"登陆！\")\n",
    "        break # 终止循环\n",
    "\n",
    "# 情景二：账号不存在或密码不正确\n",
    "    else:\n",
    "        if i == 1:\n",
    "            print(\"三次输入失败，请1小时后再来尝试\")\n",
    "        print(\"账号不存在或密码不正确!\")\n",
    "        print(\"您还有\"+str(i-1)+\"次尝试的机会\") # str将强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：肥\n",
      "年龄：19\n",
      "工作：自媒体\n",
      "收入：3w\n",
      "地区：中国\n",
      "-----INFO OF-----肥------\n",
      "年龄:19\n",
      "工作:自媒体\n",
      "收入:3w\n",
      "地区:中国\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法一：字符串拼接\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info =  '''-----INFO OF-----'''+ name +'''------'''+'''\n",
    "年龄:'''+age+'''\n",
    "工作:'''+job+'''\n",
    "收入:'''+salary+'''\n",
    "地区:'''+reg\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# input 作为用户输入，其都以字符串形式返回\n",
    "age = input(\"姓名\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：肥\n",
      "年龄：19\n",
      "工作：this\n",
      "收入：3w\n",
      "地区：中国\n",
      "-----INFO OF 肥-----\n",
      "年龄:19\n",
      "工作:this\n",
      "收入:3w\n",
      "地区:中国\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法二：占位符%s,依次有序输入\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info =  '''-----INFO OF %s-----\n",
    "年龄:%s\n",
    "工作:%s\n",
    "收入:%s\n",
    "地区:%s'''%(name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：肥\n",
      "年龄：\n",
      "工作：\n",
      "收入：\n",
      "地区：\n",
      "-----INFO OF {姓名}-----\n",
      "年龄:{姓名}\n",
      "工作:{年龄}\n",
      "收入:{收入}\n",
      "地区:{地区}\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法三： format()格式化输出函数\n",
    "name = input(\"姓名：\")\n",
    "age = (input(\"年龄：\")) # 强制将str转换成int\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info =  '''-----INFO OF {姓名}-----\n",
    "年龄:{姓名}\n",
    "工作:{年龄}\n",
    "收入:{收入}\n",
    "地区:{地区}'''\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
